mini.parse();
var grid = mini.get("ReportRepairGrid");
grid.setSortField("UPDATE_TIME");
grid.setSortOrder("desc");
grid.load();
var projectName = $("#projectName").val();

function editReportRepair(row) {
	if(row){
		openWindowsReportRepair(row.id,"edit","编辑");
	 }else{
		 row = grid.getSelected();
		if(row){
			openWindowsReportRepair(row.id,"edit","编辑");
		}else{
			  mini.alert("请选中一条记录");
		}
	} 	
}
function openWindowsReportRepair(id,openType,WindowName){
	mini.open({
        url: projectName+"/ReportRepairAdmin/EditPage",
        title: WindowName, width: 700, height: 500,
        onload: function () {
            var iframe = this.getIFrameEl();
            var data = { action: openType, id: id };
            iframe.contentWindow.CheckEventReportRepair(data);
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}
function addReportRepair(){
	openWindowsReportRepair("","new","新增");
}

function onrowdblclick(e){
	 var record = e.record;
	openWindowsReportRepair(record.id,"look","查看");
}


function seachRow(){
	var form = new mini.Form("#formseach");
    var data = form.getData(true, false);
    grid.load(data);
	
}
function resetForm(){
	 var form = new mini.Form("#formseach");
     form.reset();
}
function exportReportRepair() {
	var rows = grid.getSelecteds();
	var idString = '';
	var url = projectName +"/ReportRepairAdmin/exportReportRepairExcel?";
    if (rows.length > 0) {
	    var ids = [];
	    for (var i = 0, l = rows.length; i < l; i++) {
	        var r = rows[i];
	        ids.push(r.id);
	    }
	    idString = ids.join(',');    
	    mini.get("ids").setValue(idString);
	    util.exportDataToClient($('#ReportRepairListForm'), url);
	} else {
		
		mini.confirm('导出全部？如查询条件不为空，则导出符合查询条件的所有数据.','确定？',function(action) {
			if (action == 'ok') {
				mini.get('ids').setValue('');
				util.exportDataToClient($('#ReportRepairListForm'), url);
			} else {
				window.close();
			}
		});
	}
}	

function removeReportRepair(){
	var rows = grid.getSelecteds();
    if (rows.length > 0) {
    	mini.confirm('确定删除选中记录？','确定？',function(action) {
    		if (action == 'ok') {
                var ids = [];
                for (var i = 0, l = rows.length; i < l; i++) {
                    var r = rows[i];
                    ids.push(r.id);
                }
                var idString = ids.join(',');
                
                $.ajax({
                    url: projectName+"/ReportRepairAdmin/batchDelReportRepair?ids=" +idString,
                    type : 'post',
                    dataType : 'json',
                    success: function (data, textStatus, jqXHR) {
                    	if (data.status == '0' || data.status == '1') {
                    		mini.alert(data.message, '', function() {
    							grid.reload();
    						});
    					} else {
    						mini.alert("发生错误!", '', function() {
    							grid.reload();
    						});
    					}
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                    	mini.alert("发生错误，操作失败！");
                    }
                });
             
    		} else {
    			window.close();
    		}
    	});
    	
    } else {
        mini.alert("请选中一条记录");
    }

}

function importReportRepair(){
	mini.open({
        url: projectName+"/AttachmentAdmin/importExcelPage?configName=ReportRepairEntityExcel&importType=add",
        title: "数据导入", width: 700, height: 500,
        onload: function () {
            var iframe = this.getIFrameEl();
            var data = { action: openType, id: id };
            iframe.contentWindow.CheckEventReportRepair(data);
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

/**查看详情*/
function viewReportRepairDetail(){
	
}
/**查看条码*/
function viewReportRepairBarcode(){
	 var rows = grid.getSelecteds();
	 var l = rows.length;
	 if(l==0){
		 mini.alert("请选择一条记录");
		 return;
	 }else if(l>1){
		 mini.alert("只能选择一条记录");
		 return;
	 }
	 var row = rows[0];
	mini.open({
        url: projectName+"/ReportRepairBarcodeAdmin/ListPage",
        title: "查看条码", width: 700, height: 500,
        onload: function () {
            var iframe = this.getIFrameEl();
            iframe.contentWindow.setDefaultParam(row);
        },
        ondestroy: function (action) {
        	
        }
    });
	/*
	if(row){
		mini.open({
			url:projectName+"/ReportRepairBarcodeAdmin/ListPage",
			title:"查看条码",
			width:700,
			height:500,
			onload:function(){
				var iframe = this.getIFrameEl();
				var data = {action:"edit",id:row.id};
				iframe.contentWindow.SetData(data);
			},
			ondestory:function(action){
				grid.reload();
			}
		});
	}else{
		mini.alert("请选择一条记录");
	}*/
}

/**分公司改变*/
function onChangeBranch(e){
	var orgId = e.value;
	var office = mini.get("officeOrgId");
	var url = projectName+"/OrgAdmin/queryList?orgType=2&parentOrgId="+orgId;
	office.setUrl(url);
}

function onShopGenderAction(){
	return "已完成";
}

function onSelectShop(e){
	var orgId = mini.get("officeOrgId").getValue();
	if(!orgId){
		orgId = mini.get("branchOrgId").getValue();
	}
    var btnEdit = this;
    mini.open({
        url: projectName+"/ShShopAdmin/shopChoose",
        title:"店铺选择", width: 780, height: 500,
        onload: function () {
            var iframe = this.getIFrameEl();
            var data = {orgId:orgId,chooseType:"true"};
            iframe.contentWindow.setData(data);
        },
        ondestroy: function (action) {
        	if (action == "ok") {
                var iframe = this.getIFrameEl();
                var data = iframe.contentWindow.GetData();
                data = mini.clone(data);
                var rows = data.rows;
                var row = rows[0];
                btnEdit.setValue(row.shopNumId);
                btnEdit.setText(row.shopName);
            }
        }
    });
}
